// * 现有如下json（简化为对象），已知每个节点id唯一，编写findNode(id)，返回路径，如findNode(5) 输出 1->4->5
json = {
    id: 1,
    children: [
        { id: 2, children: [{ id: 3, children: [] }] },
        {
            id: 4,
            children: [
                { id: 5, children: [] },
                { id: 6, children: [] },
            ],
        },
        { id: 7, children: [] },
    ],
};
function findNode(json,findId) {

    function recur(json,findId,route) {
        const {id, children} = json
        route += id
        if (id === findId) {
            res = route
            return
        }
        if (children) {
            children.forEach(item=>{

                recur(item,findId,route + '->')
            })
        }
    }
    let route = ''
    let res
    recur(json,findId,route)
    return res
}

console.log(findNode(json, 6));
